
<div class="form-option spmsxx">
    <div class="form-group row">
        <label class="col-md-2 control-label fc-sku-group-html">商品价格</label>
        <div class="col-md-9 ">
            ￥<span id="dr_sku_price">{if $price_sku}{dr_sku_price($price_sku, 2, ' ~ ')}{else}{dr_price_value($price, 2)}{/if}</span>元
        </div>
    </div>
    <div class="form-group row">
        <label class="col-md-2 control-label fc-sku-group-html">商品编号</label>
        <div class="col-md-9 ">
            <span id="dr_sku_sn"> {$price_sn} </span>
        </div>
    </div>
    {if $price_sku}
    {loop $price_sku['group'] $gid $gname}
    {if $gname}
    <div class="form-group row">
        <label class="col-md-2 control-label fc-sku-group-html">{$gname}</label>
        <div class="col-md-9 fc-sku-select-price">
            {php $i=0;}
            {loop $price_sku['name'][$gid] $vid $vname}
            <button type="button" fvalue="{$gid}_{$vid}" fname="{$vname}" fsn="{$price_sku['value'][$gid.'_'.$vid]['sn']}" class="fc-sku-value btn {if $i==$sku_value[$gid]}red{/if} btn-default btn-xs">{$vname}</button>
            {php $i=1;}
            {/loop}
        </div>
    </div>
    {/if}
    {/loop}
    <input type="hidden" id="dr_sku_value" value="">
    {loop $price_sku['value'] $i $v}
    <input type="hidden" id="dr_sku_sn_{$i}" value="{$v.sn}">
    <input type="hidden" id="dr_sku_price_{$i}" value="{number_format($v.price,2)}">
    <input type="hidden" id="dr_sku_quantity_{$i}" value="{$v.quantity}">
    <input type="hidden" id="dr_sku_promotion_{$i}" value="{$promotion[$i]}">
    {/loop}
    {/if}
    <div class="form-group row">
        <label class="col-md-2 control-label fc-sku-group-html">库存剩余</label>
        <div class="col-md-9">
            <span id="dr_sku_quantity"> {$price_quantity} </span>件
        </div>
    </div>
    <div class="form-group row">
        <label class="col-md-2 control-label fc-sku-group-html" >购买数量</label>
        <div class="col-md-2">
            <input id="dr_buy_num" type="text" value="1">
        </div>
    </div>

    <div class="form-group row">
        <label class="col-md-2 control-label fc-sku-group-html">&nbsp;</label>
        <div class="col-md-5">
            <a href="javascript:order_{dirname}_add_buy();" class="btn green"> <i class="fa fa-rmb"></i> 立即购买 </a>
            <a href="javascript:order_{dirname}_add_cart();" class="btn red"> <i class="fa fa-shopping-cart"></i> 加入购物车 </a>
        </div>
    </div>

</div>


<link href="{THEME_PATH}assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.css" rel="stylesheet" type="text/css" />
<script src="{THEME_PATH}assets/global/plugins/fuelux/js/spinner.min.js" type="text/javascript"></script>
<script src="{THEME_PATH}assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.js" type="text/javascript"></script>

<script type="text/javascript" src="{THEME_PATH}assets/js/sku.js"></script>
<script type="text/javascript">
    $(function () {
        order_{dirname}_select_sku_price();
        order_{dirname}_get_sku_price();
        $("#dr_buy_num").TouchSpin({
            step: 1,
            min: 1,
            max: {intval($price_quantity)}
        });
    })
    // 加入购物车
    function order_{dirname}_add_cart(){
        $.get("/index.php?is_ajax=1&s=order&c=cart&m=add&mid={MOD_DIR}&num="+$('#dr_buy_num').val()+"&id={$id}&sku="+$('#dr_sku_value').val(), function(data){
            dr_cmf_tips(data.code, data.msg);
            if (data.code) {
                // 存储购物车数量
                $('#dr_order_{dirname}_cart_nums').html(data.data);
            }
        }, 'json');
    }
    // 购买地址
    function order_{dirname}_add_buy() {
        var url = "{dr_url('order/order/buy', ['mid' => MOD_DIR, 'id'=>$id])}";
        url+= "&sku="+$('#dr_sku_value').val();
        url+= "&num="+$('#dr_buy_num').val();
        window.location.href = url;
    }
    // 组合价格选择
    function order_{dirname}_select_sku_price() {
        $('.fc-sku-select-price .fc-sku-value').click(function () {
            $(this).parent('.fc-sku-select-price').find('.fc-sku-value').removeClass('red');
            $(this).addClass('red');
            order_{dirname}_get_sku_price();
        });
    }
    function order_{dirname}_get_sku_price() {
        var oname = new Array();
        $('.fc-sku-select-price').each(function () {
            oname.push($(this).find('.red').attr('fvalue'));
        });
        var k = oname.join("_");
        $('#dr_sku_value').val(k);
        $('#dr_sku_price').html($('#dr_sku_price_' + k).val());
        $('#dr_sku_quantity').html($('#dr_sku_quantity_' + k).val());
        $('#dr_sku_sn').html($('#dr_sku_sn_' + k).val());
    }
</script>